package com.ruoyi.web.controller.stock;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.domain.WarehouseOutInfo;
import com.ruoyi.stock.service.IWarehouseOutInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 出库清单Controller
 *
 * @author YwaiX
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/stock/OutInfo")
public class WarehouseOutInfoController extends BaseController {
    @Autowired
    private IWarehouseOutInfoService warehouseOutInfoService;

    /**
     * 查询出库清单列表
     */
    @PreAuthorize("@ss.hasPermi('stock:OutInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(Integer warehouseOutId) {
        startPage();
        List<WarehouseOutInfo> list = warehouseOutInfoService.selectWarehouseOutInfo(warehouseOutId);
        return getDataTable(list);
    }

    /**
     * 导出出库清单列表
     */
    @PreAuthorize("@ss.hasPermi('stock:OutInfo:export')")
    @Log(title = "出库清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarehouseOutInfo warehouseOutInfo) {
        List<WarehouseOutInfo> list = warehouseOutInfoService.selectWarehouseOutInfoList(warehouseOutInfo);
        ExcelUtil<WarehouseOutInfo> util = new ExcelUtil<WarehouseOutInfo>(WarehouseOutInfo.class);
        util.exportExcel(response, list, "出库清单数据");
    }

    /**
     * 获取出库清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('stock:OutInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(warehouseOutInfoService.selectWarehouseOutInfoById(id));
    }

    /**
     * 新增出库清单
     */
    @PreAuthorize("@ss.hasPermi('stock:OutInfo:add')")
    @Log(title = "出库清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarehouseOutInfo warehouseOutInfo) {
        return toAjax(warehouseOutInfoService.insertWarehouseOutInfo(warehouseOutInfo));
    }

    /**
     * 修改出库清单
     */
    @PreAuthorize("@ss.hasPermi('stock:OutInfo:edit')")
    @Log(title = "出库清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarehouseOutInfo warehouseOutInfo) {
        return toAjax(warehouseOutInfoService.updateWarehouseOutInfo(warehouseOutInfo));
    }

    /**
     * 删除出库清单
     */
    @PreAuthorize("@ss.hasPermi('stock:OutInfo:remove')")
    @Log(title = "出库清单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(warehouseOutInfoService.deleteWarehouseOutInfoByIds(ids));
    }
}
